<?php
namespace App\Query;

use App\Model\Order;
use App\Query\Traits\UserTrait;

class OrderQuery extends \HyperfStore\Query
{
    use UserTrait;
    
    // 构建模型
    protected static function build()
    {
        return Order::latest();
    }
    
    // 渴望加载
    protected static function with()
    {
        return ['user'];
    }
    
    // 时间区间
    protected static function queryTime($model, $where)
    {
        return $model->whereBetween('created_at', $where);
    }
    
    // 订单状态成功
    public static function statusOk($model)
    {
        return $model->where('status', Order::STATUS_OK);
    }
    
    // 已支付的订单
    public static function statusPay($model)
    {
        return $model->where('status', '>', Order::STATUS_POST);
    }
    
    // 获取可释放的订单
    public static function remain($model)
    {
        return $model->where('money_remain', '>', 0);
    }
}